﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TimKen.BussLogic;
using System.Data;

namespace TimKen.Web.Admin.Order
{
    public partial class OrderShip_Info : TimKen.App.AdminPage
    {
        ShipItemManager shipIM = new ShipItemManager();
        OrderManager orderM = new OrderManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["OrderID"] != null)
                {
                    OrderID = Request.QueryString["OrderID"];
                    BindOrder();
                    BindOrderShipItems();
                }
            }
        }

        protected string OrderID
        {
            get
            {
                if (ViewState["OrderID"] != null)
                    return (ViewState["OrderID"].ToString());
                else
                    return "";
            }
            set
            {
                ViewState["OrderID"] = value;
            }
        }
        protected void BindOrderShipItems()
        {
            DataSet orderItems = shipIM.GetOrderShipList(OrderID);
            repOrderShipItems.DataSource = orderItems;
            repOrderShipItems.DataBind();
        }

        protected void repOrderShipItems_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater itemsList = (Repeater)e.Item.FindControl("repShipItems");
                if (itemsList.Items.Count == 0)
                {
                    itemsList.Visible = false;
                    Label label = (Label)e.Item.FindControl("labNoItems");
                    label.Visible = true;
                }
            }
        }

        protected DataSet GetShipItems(string OrderItemID)
        {
            return shipIM.GetOrderItemShipList(OrderItemID);
        }

        protected void BindOrder()
        {
            TimKen.DataEntity.Order order = orderM.GetModel(OrderID);
            TransTypeManager tm = new TransTypeManager();
            labCreateDate.Text = order.CreateDate.ToShortDateString();
            labEmail.Text = order.Email;
            labBillAddress.Text = order.BillAddress;
            labContractStatus.Text = order.ContractStatus.HasValue ? (order.ContractStatus.Value == 0 ? GetLangString("ForConfirm") : GetLangString("Confirmed")) : "";
            labOrderID.Value = order.OrderID;
            labOrderNo.Text = order.OrderNo;
            labOrderStatus.Text = orderM.GetOrderStatusName(order.OrderStatus, LanguageID);
            labRemark.Text = order.Remark;
            labSalesPersonCode.Text = order.SalesPersonCode.ToString();
            labShipAddress.Text = order.ShipAddress;
            labShipTo.Text = order.Country;
            labTransType.Text = tm.GetModel(order.ShipType.Value, LanguageID).TransTypeName;
            labContactPerson.Text = order.CntctCode;
            labLMName.Text = order.ContactPerson;
            labMobile.Text = order.Mobile;
            labTelephone.Text = order.Telephone;
            labAddress.Text = order.Address;
        }
    }
}
